Week 15
Networking and Communications
design and build a wired &/or wireless network connecting at least two processors
I wanted to connect my input and output board for the networking week. The idea was that the value of light intensity detected using the input board would be displayed on the LCD display of the output board.
Basically, there are three methods: Serial, SPI and I2C.
Serial
Here data is send one bit at a time, sequentially, over a communication channel or computer bus.
SPI
Serial Peripheral Interface or in short SPI is an interface bus commonly used to send data between microcontrollers and small peripherals such as shift registers, sensors, and SD cards. It uses separate clock and data lines, along with a select line to choose the device you wish to talk to.
I2C
The Inter-integrated Circuit or I2C Protocol is a protocol that intends to allow multiple “slave” digital integrated circuits (“chips”) to communicate with one or more “master” chips. Just like the Serial Peripheral Interface (SPI), it is only intended for short distance communications within a single device.
Features
- Uses ISP pins also for communication. Downside is that some pins are shared.
- Has LED for output, switch for input.
- Has through hole as well as smd mounting for ftdi access.
All three nodes have an ATtiny45 microcontroller. The boards are designed in Eagle based on the class example .
For the bridge board, I have added also a second led to indicate power. The 2x3 pin header is used for programming the microcontroller. The 2x2 header is used to connect the databus (DB) pins RX and TX to the microcontroller and to connect power and GND. The led pin is PB0.
I decided to make i2C communication containing One master and One slave.
Basically we can show the I2C communication as
I2C bus is popular because it is simple to use, there can be more than one master, only upper bus speed is defined and only two wires with pull-up resistors are needed to connect almost unlimited number of I2C devices. I2C can use even slower micro controllers with general-purpose I/O pins since they only need to generate correct Start and Stop conditions in addition to functions for reading and writing a byte.
Each slave device has a unique address. Transfer from and to master device is serial and it is split into 8-bit packets. All these simple requirements make it very simple to implement I2C interface even with cheap micro controllers that have no special I2C hardware controller. You only need 2 free I/O pins and few simple i2C routines to send and receive commands.
I2C uses only two wires: SCL (serial clock) and SDA (serial data). Both need to be pulled up with a resistor to +Vdd. There are also I2C level shifters which can be used to connect to two I2C buses with different voltages.
Node1 and Node2 boards: Eagle schematics and board; png files for milling traces
This is the reference board trace which I used to design the Master Board.
I inserted the Components for the master board. Made the connections required as per the reference above .After completion of Schematic,i generated corresponding board file as shown below
Master board design
I created eagle file and inserted the Components like Attiny,resistors,Capacitor and Connection headers as well in the schematic.
Eagle Schematic Design
then I generated corresponding Board file as below.
Slave Board file
CAM processing:
I made .cmp file to mill from the Cirqoid machine and loaded in the Cirqwizard application.
I soldered the components in to the boards and I got the boards as follows.
Programming
Before programming I burned boot loader on each board and it was successful.
Then after that I programmed master with master board program and slaves with slaves board program.
Master program
#include < TinyWireM.h>
void setup()
{
TinyWireM.begin(); // join i2c bus (address optional for master)
}
byte x = 0;
byte x1 = 0;
void loop() {
TinyWireM.beginTransmission(0x4);
TinyWireM.write(++x % 2);
TinyWireM.endTransmission();
delay(1000);
TinyWireM.beginTransmission(0x3);
TinyWireM.write(++x1 % 2);
TinyWireM.endTransmission();
delay(1000);
}
Slave board
for 1-
#define output(directions, pin) (directions |= (1 << pin)) // set port direction for output
#define input(directions, pin) (directions &= (~(1 << pin))) // set port direction for input
#define set(port, pin) (port |= (1 << pin)) // set port pin
#define clear(port, pin) (port &= (~(1 << pin))) // clear port pin
#define LED_PIN PB4
#define I2C_SLAVE_ADDRESS 0x1 // Address of the slave 2
#include <TinyWireS.h>
void setup()
{
output(DDRB, LED_PIN);
clear(PORTB, LED_PIN);
TinyWireS.begin(I2C_SLAVE_ADDRESS); // join i2c network
}
void loop()
{
byte recd = 1;
if(TinyWireS.available()) {
recd = TinyWireS.receive();
if(recd == 1) {
clear(PORTB, LED_PIN);
} else {
set(PORTB, LED_PIN);
}
}
}
for slave 2-
#define output(directions, pin) (directions |= (1 << pin)) // set port direction for output
#define input(directions, pin) (directions &= (~(1 << pin))) // set port direction for input
#define set(port, pin) (port |= (1 << pin)) // set port pin
#define clear(port, pin) (port &= (~(1 << pin))) // clear port pin
#define LED_PIN PB4
#define I2C_SLAVE_ADDRESS 0x2 // Address of the slave 1
#include <TinyWireS.h>
void setup()
{
output(DDRB, LED_PIN);
clear(PORTB, LED_PIN);
TinyWireS.begin(I2C_SLAVE_ADDRESS); // join i2c network
}
void loop()
{
byte recd = 1;
if(TinyWireS.available()) {
recd = TinyWireS.receive();
if(recd == 1) {
clear(PORTB, LED_PIN);
} else {
set(PORTB, LED_PIN);
}
}
Output Video